-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(grouping): Simplify handling of variant name and exception data #97458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(grouping): Simplify handling of variant name and exception data #97458
Conversation
^ Conflicts: ^ src/sentry/grouping/strategies/message.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good 🎉 , minor comment
@@ -27,9 +27,6 @@ | |||
], | |||
delegates=["frame:v1", "stacktrace:v1", "single-exception:v1"], | |||
initial_context={ | |||
# This key in the context tells the system which variant should | |||
# be produced. TODO: phase this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah the joy of removing a 4 year old TODO in code :)
@@ -72,15 +72,17 @@ def normalize_message_for_grouping(message: str, event: Event) -> str: | |||
def message_v1( | |||
interface: Message, event: Event, context: GroupingContext, **kwargs: Any | |||
) -> ReturnedVariants: | |||
variant_name = context["variant_name"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the code previously didnt, but should we not asserting for existence here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The produces_variants
decorator (indirectly) sets variant_name
in the context, so we know it will be there.
(To be more precise, the decorator calls call_with_variants
, and call_with_variants
sets variant_name
immediately before calling strategy_func
, which in this case is the function message_v1
that you're looking at.)
…97458) During grouping, we pass data from one component strategy to another by storing it in the grouping context. In that context, two values - the variant name and a blob of exception data - are only sometimes defined. Until recently, the `GroupingContext` class supported key-lookup using subscript notation (`context[some_key]`) the same way a dictionary would, but lacked the safer `.get()` method. We therefore currently initialize both values to `None`, to prevent raising a `KeyError` if the values haven't been set. Now that `.get()` has been implemented, though, we don't need to do that. This PR therefore switches the way we access them to use `.get()`, and removes the default initialization. In order to enforce when `variant_name` is or isn't expected to be defined, it also extends the practice already followed in some strategies of asserting on its existence (or lack thereof). This ensures that if we ever make changes to the grouping code, we'll know right away if our assumptions have been violated.
During grouping, we pass data from one component strategy to another by storing it in the grouping context. In that context, two values - the variant name and a blob of exception data - are only sometimes defined. Until recently, the
GroupingContext
class supported key-lookup using subscript notation (context[some_key]
) the same way a dictionary would, but lacked the safer.get()
method. We therefore currently initialize both values toNone
, to prevent raising aKeyError
if the values haven't been set.Now that
.get()
has been implemented, though, we don't need to do that. This PR therefore switches the way we access them to use.get()
, and removes the default initialization. In order to enforce whenvariant_name
is or isn't expected to be defined, it also extends the practice already followed in some strategies of asserting on its existence (or lack thereof). This ensures that if we ever make changes to the grouping code, we'll know right away if our assumptions have been violated.